from PyQt4.QtGui import QGraphicsEllipseItem, QGraphicsWidget, QGraphicsTextItem, \
    QGraphicsItem, QGraphicsItemGroup, QTextDocument, QTextOption, QGraphicsRectItem
from PyQt4.QtCore import QRectF, QPointF, Qt
from logging import config, getLogger
import math

config.fileConfig('logging.conf')
logger = getLogger('dodo.mindmap')

class NodeWidget(QGraphicsItemGroup):
    
    def __init__(self):
        super(NodeWidget, self).__init__()
        
        # Set the bounding box for this widget
        self._boundingRect = QRectF()
        self._boundingRect.setHeight(150)
        self._boundingRect.setWidth(150)
        self._boundingRect.moveCenter(QPointF(0,0))
        
        # Set the size and shape
        self.background = QGraphicsEllipseItem(self._boundingRect,self)
        
        opts = QTextOption()
        opts.setAlignment(Qt.AlignCenter)
        opts.setWrapMode(QTextOption.WrapAtWordBoundaryOrAnywhere)
        
        text_width = self._boundingRect.width()/math.sqrt(2)
        
        self.title = QGraphicsTextItem("Hello World. This is Bob. Nice to meet you!")
        doc = self.title.document()
        doc.setDefaultTextOption(opts)
        doc.setTextWidth(text_width)
        self.title.setDocument(doc)
        
        self.title.setPos(-text_width/2,-text_width/2)
        
        self.addToGroup(self.background)
        self.addToGroup(self.title)
        
    def boundingRect(self):
        return self._boundingRect

class LinkWidget(QGraphicsWidget):
    pass